package com.sc.nft.admin.controller;

import cn.hutool.core.util.StrUtil;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.ExamineAndApproveDTO;
import com.sc.nft.entity.dto.ServiceCenterAuditDTO;
import com.sc.nft.entity.vo.ServiceCenterAuditDetailsVO;
import com.sc.nft.entity.vo.ServiceCenterAuditVO;
import com.sc.nft.service.ServiceCenterAuditService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * (ServiceCenterAudit)表控制层
 *
 * @author wwc
 * @since 2023-07-18 14:41:32
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/serviceCenterAudit")
@Api(tags = "服务中心审核")
public class ServiceCenterAuditController {

    /**
     * 服务对象
     */
    private final ServiceCenterAuditService serviceCenterAuditService;

    @PostMapping(value = "/compactPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "简介分页", notes = "简介分页", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<ServiceCenterAuditVO> compactPage(@Valid @RequestBody ServiceCenterAuditDTO serviceCenterAuditDTO) {
        return PageResult.success(serviceCenterAuditService.compactPage(serviceCenterAuditDTO));
    }

    @PostMapping(value = "/getById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "根据id获取所有详情信息", notes = "根据id获取所有详情信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<ServiceCenterAuditDetailsVO> getById(@Valid @RequestBody IdRequest idRequest) {
        return Result.success(serviceCenterAuditService.getById(idRequest.getId()));
    }

    @PostMapping(value = "/examineAndApprove", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "审批", notes = "审批", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result examineAndApprove(@Valid @RequestBody ExamineAndApproveDTO examineAndApproveDTO) {
        if (examineAndApproveDTO.getStatus().equals(2)) {
            if (StrUtil.isBlank(examineAndApproveDTO.getRefuse())) {
                return Result.fail("拒绝原因不能为空");
            }
        }
        serviceCenterAuditService.examineAndApprove(examineAndApproveDTO);
        return Result.success();
    }

}
